extends Node

signal health_changed
signal health_depleted

enum Statuses {NONE, INVINCIBLE}

export(int) var max_health = 100

var health = 0
var status


func _ready() -> void:
	health = max_health
	_change_status(Statuses.NONE)


func kill():
	health = 0
	emit_signal("health_depleted")
	emit_signal("health_changed", health)
	_change_status(Statuses.NONE)

func take_damage(amount: int) -> void:
	if status == Statuses.INVINCIBLE:
		return
	print ("%s took %s damage. Health: %s/%s" % [get_path(), amount, health, max_health])
	health -= amount
	if health <= 0:
		health = 0
		emit_signal("health_depleted")
		
	emit_signal("health_changed", health)


func recover_health(amount: int) -> void:
	health += amount
	if health > max_health:
		health = max_health
	emit_signal("health_changed", health)
	print ("%s recovered %s health. Health: %s/%s" % [get_path(), amount, health, max_health])


func _change_status(new_status) -> void:
	status = new_status
